#!/usr/bin/env node

const log = console.log,
      http = require('http'),
      url = require('url'),
      addr = 'http://www.sian.com/';

let opt = (ad)=>{
  let p = url.parse(ad);
  p.headers={
    'user-agent':'curl/7.29.0'
  }
  return p;
};

log(opt(addr));

const get = (opt)=>{
  http.get(opt,res=>{
  
    log(`HTTP/${res.httpVersion} ${res.statusCode} ${res.statusMessage}`);
    log(res.headers);

    if(res.statusCode < 400 && res.statusCode >= 300){
      get(opt(res.headers.location));

    }else{
      res.pipe(process.stdout)
    }

  
  })
}

get(opt(addr));
